<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<script type="text/javascript">
var doOnsubmit = function(){
	if($("#addressId").val()=="" ) {
		alert("请选择地址!");
		return false;
	}
	return true;
}
var changeAddress = function(index,id,addr, postcode, phone, tel) {
	$("div[id^='address_']").css("background","#FFFFFF").css("border","1px solid #FFFFFF");
	$("#address_"+index).css("background","lightblue").css("border","1px solid red");
	$("#addressId").val(id);
}
</script>

<form method="post" action="order/selectAddress.do" onsubmit="return doOnsubmit()">
	<s:hidden name="order.id" />
	<s:hidden name="addressId" />
	<s:hidden name="orderId" value="%{order.id}" />
	<div id="address_desc" class="box">
		<s:if test="selectAddress != null">
			<div>
				你已经加入过该订单，且设置了如下收货地址：
			</div>
			<div>
				&nbsp;&nbsp;
				<i>您所选择的收货地址为:<s:property value="selectAddress.address" />,邮编为:<s:property value="selectAddress.postcode" /> ,手机号码为:<s:property value="selectAddress.phone" />,电话为:<s:property value="selectAddress.tel" /> </i>
			</div>
		</s:if>
	</div>
	<div class="box">
		<s:if test="selectAddress==null">
		<div class="notice">请选择收货地址：</div>
		<s:iterator value="addresses" id="item" status="status">
				<div style="margin-left: 20px" id="address_<s:property value="#status.index"/>" class="selectitem" 
					 onclick="javascript:changeAddress('<s:property value="#status.index"/>','<s:property value="#item.id"/>');">
					<s:if test="%{selectAddress != null && selectAddress.id.equals(#item.id)}">
						<script type="text/javascript">
								changeAddress('<s:property value="#status.index"/>','<s:property value="#item.id"/>');
								</script>
					</s:if>
					<ul style="border-bottom: 1px dotted gray;">
						<li>
							地区:
							<s:property value="#item.region.fullName" />
						</li>
						<li>
							地址:
							<s:property value="#item.address" />
							( 邮编:
							<s:property value="#item.postcode" />
							)
						</li>
						<li>
							手机:
							<s:property value="#item.phone" />
						</li>
						<li>
							电话:
							<s:property value="#item.tel" />
						</li>
					</ul>
				</div>
			</s:iterator>
		</s:if>
		<br />
		<input type="submit" class="btn_yellow_3" value="确定">
		如果以上地址都不是不是你想要送货地址，点击
		<a href="#" onclick="javascript:$('#addressBox').show();">这里</a>添加新地址。
	</div>
</form>
<div id="addressBox" class="box_blue" style="display: none;">
	<div class="box_title">
		创建新地址
	</div>
	<form method="post" action="order/selectAddress.do" onsubmit="javascript:return isAddressFillAll();">
		<s:hidden name="order.id" />
		<s:hidden name="orderId" value="%{order.id}" />
		<jsp:include page="/address/address_edit_table.jsp"></jsp:include>
		<input type="submit" value="提交">
	</form>
</div>